home *** CD-ROM | disk | FTP | other *** search
/ The Arsenal Files 8 / The Arsenal Files Collection #8 (Arsenal Computer) (1996).ISO / prg_gen / euphor14.zip / LEARN.EX < prev    next >
Text File  |  1996-04-05  |  3KB  |  111 lines

  1.     -----------------------------------------------
  2.     -- A Quiz to Test Your Knowledge of Euphoria --
  3.     -----------------------------------------------
  4. include get.e
  5. include graphics.e
  6.  
  7. constant NTRYS = 3
  8. constant KEYBOARD = 0, SCREEN = 1
  9.  
  10. procedure get_answer(object correct)
  11.     sequence answer
  12.     atom t
  13.  
  14.     for i = 1 to NTRYS do
  15.     answer = get(KEYBOARD)
  16.     puts(SCREEN, '\n')
  17.     if answer[1] = GET_SUCCESS then
  18.         if compare(answer[2], correct) = 0 then
  19.         puts(SCREEN, "Correct!\n\n")
  20.         sound(2000)
  21.         t = time()
  22.         while time() < t+0.1 do
  23.         end while
  24.         sound(0)
  25.         return
  26.         elsif i < NTRYS then
  27.         puts(SCREEN, "Try again\n")
  28.         sound(200)
  29.         t = time()
  30.         while time() < t+0.4 do
  31.         end while
  32.         sound(0)
  33.         end if
  34.     else
  35.         puts(SCREEN, "syntax error - a Euphoria object is expected\n")
  36.         while getc(KEYBOARD) != '\n' do
  37.         end while
  38.     end if    
  39.     end for
  40.     puts(SCREEN, "The correct answer was: ")
  41.     print(SCREEN, correct)
  42.     puts(SCREEN, '\n')
  43. end procedure
  44.  
  45. procedure part1()
  46. -- evaluating simple expressions
  47.     object x, y
  48.  
  49.     puts(SCREEN, "Please evaluate the following Euphoria expressions\n")
  50.     puts(SCREEN, "You have 3 guesses.\n\n")
  51.  
  52.     x = rand(10)
  53.     y = rand(10)
  54.     printf(SCREEN, "%d + %d\n", {x, y})
  55.     get_answer(x + y)
  56.  
  57.     x = rand(repeat(10, 3))
  58.     y = rand(10)
  59.     print(SCREEN, x)
  60.     puts(SCREEN, " * ")
  61.     print(SCREEN, y)
  62.     puts(SCREEN, '\n')
  63.     get_answer(x * y)
  64.  
  65.     x = rand(repeat(10, 4)) - 5
  66.     y = rand(repeat(10, 4)) - 5
  67.     print(SCREEN, x)
  68.     puts(SCREEN, " > ")
  69.     print(SCREEN, y)
  70.     puts(SCREEN, '\n')
  71.     get_answer(x > y)    
  72.  
  73.     x = rand(20)
  74.     y = rand(5)
  75.     puts(SCREEN, "repeat(")
  76.     print(1, x)
  77.     puts(SCREEN, ", ")
  78.     print(1, y)
  79.     puts(SCREEN, ")\n")
  80.     get_answer(repeat(x, y))
  81.     
  82.     x = rand(repeat(25, 3)) + 'a'
  83.     y = rand(repeat(25, 2)) + 'a'
  84.     printf(SCREEN, "\"%s\" & \"%s\"\n", {x, y})
  85.     get_answer(x & y)
  86.  
  87.     x = rand(repeat(99,3))
  88.     y = rand(repeat(99,2))
  89.     puts(SCREEN, "append(")
  90.     print(SCREEN, x)
  91.     puts(SCREEN, ", ")
  92.     print(SCREEN, y)
  93.     puts(SCREEN, ")\n")
  94.     get_answer(append(x, y))
  95.     
  96.     puts(SCREEN, "what will the value of x be\n")
  97.     puts(SCREEN, "after executing the following statements?\n")
  98.     puts(SCREEN, "x = ")
  99.     x = rand({10, 10, {10, 10, 10, 10}, 20})
  100.     print(SCREEN, x)
  101.     y = rand({20, 20, 20, 20, 20})
  102.     puts(SCREEN, "\ny = ")
  103.     print(SCREEN, y)
  104.     puts(SCREEN, "\nx[3][2..3] = y[4..5]\n")    
  105.     x[3][2..3] = y[4..5]
  106.     get_answer(x)
  107. end procedure
  108.  
  109. part1()   -- quick questions
  110.  
  111.